<template>
  <div class="content-div">
    <div class="content-box">
      <div class="module-box">
        <div @click="toServicePage('/productList', {type: item.type}, item.text)" class="item-box" v-for="(item, index) in moduleList" :key="index">
          <img :src="item.img" alt="" srcset="">
          <span>{{item.text}}</span>
        </div>
      </div>
      <div class="module2-box">
        <img @click="toServicePage('/productDetail', {give_service_id:'1', give_service_type: '就医陪诊'}, '一对一陪护')" src="@/assets/images/mk-jypz.png" alt="" srcset="">
        <img @click="toServicePage('/productDetail', {give_service_id:'2', give_service_type: '院内陪护'}, '院内陪护')" src="@/assets/images/mk-ynph.png" alt="" srcset="">
      </div>
      <div class="module2-box">
        <span>一对一就医陪诊</span>
        <span>院内陪护</span>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from 'vant'
import { selectGiveServiceCityList } from '@/api/medical.js'
export default {
  name: 'index',
  data () {
    return {
      moduleList: [
        { id: '1', text: '诊前预约', img: require('@/assets/images/icon-zqyy.png') },
        { id: '1', text: '代办问诊', img: require('@/assets/images/icon-dbwz.png') },
        { id: '1', text: '代办买药', img: require('@/assets/images/icon-dbmy.png') },
        { id: '1', text: '送取结果', img: require('@/assets/images/icon-sqjg.png') },
        { id: '1', text: '就医陪诊', img: require('@/assets/images/icon-jypz.png') }
      ],
      serviceList: []
    }
  },
  created () {},
  methods: {
    toPage (url) {
      this.$router.push(url)
    },
    getService () {
      selectGiveServiceCityList({
        province: this.$store.state.app.city.province_code,
        city: this.$store.state.app.city.city_code
      }).then(res => {
        if (res.data.errcode === 0) {
          this.serviceList = res.data.data
        }
      })
    },
    toServicePage (path, query, name) {
      let isGo = false
      this.serviceList.forEach(item => {
        if (item.give_service_name === name) {
          isGo = true
        }
      })
      if (!isGo) {
        Toast.fail('暂无此服务')
        return false
      }
      this.$router.push({
        path,
        query
      })
    }
  },
  mounted () {
    this.getService()
  }
}
</script>

<style scoped lang="less">
  .content-div{
    font-size: 12px;
    min-height: 100%;
    background-image: url('../../../../assets/images/bg.png');
    background-repeat: no-repeat;
    background-size: 100% auto;
    position: relative;
    .content-box{
      position: absolute;
      bottom: 80px;
      left: 0;
      .module-box{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 300px;
        margin-left: 10px;
        padding-top: 10px;
        padding-bottom: 30px;
        .item-box{
          font-size: 12px;
          color: #000000;
          display: flex;
          flex-direction: column;
          align-items: center;
          img{
            width: 38px;
            height: 38px;
            margin-bottom: 6px;
          }
        }
      }
      .module2-box{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        width: 300px;
        margin-left: 10px;
        padding-bottom: 4px;
        img{
          width: calc((100% - 10px) / 2);
          height: 100%; // 不然图片被纵向拉伸了
        }
        span{
          width: calc((100% - 10px) / 2);
          text-align: center;
        }
      }
    }
  }
</style>
